import axios from 'axios'
let qs = require('qs')

let baseURL = 'http://www.th-coin.com:90/'
// let baseURL = 'http://192.168.2.129:90/'
// let baseURL = 'http://block.jinanluke.com:90'

axios.defaults.withCredentials = true
let tpost = axios.create({
	baseURL,
	headers: {
		'Content-Type': 'multipart/form-data',
	},
	method: 'post',
})

let showResult = re => {
	// 测试环境用来看请求的结果
	console.log(re)
}

tpost.interceptors.response.use(
	function(response) {
		let re = response.data
		showResult(re)
		return re
	},
	function(error) {
		return false
	},
)

let vpost = (link, setting) => {
	let s = qs.stringify(setting)
	showResult(s)
	return tpost.post(link, s)
}

let getRan = () => {
	// 获取一个随机数, 一些借口要用到
	return (Math.random() * 100) | 0
}
let vlink = {
	auth: 'user/validateIdentity.html?random=' + getRan(), // 实名认证
}

export { vpost, vlink }
